﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoolanElement.UI.Table;
using BoolanSlide.UIElement.Table.Operation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace BoolanSlide.UIElement.Table.Structure.Element
{
    public class BooTableElementUnit
    {
        public BooTableDataUnit Data;
        public BooTableStyleUnit Style;
        public event TablePropertyChangedHandler TablePropertyChanged;
        public String RichText
        {
            set
            {
                Data.DataString = value;
                TablePropertyChangedArgs arg = new TablePropertyChangedArgs();
                arg.PropertyName = "RichText";
                arg.Operation = TablePropertyChangedArgs.ChangeProperty;
                arg.RichText = value;
                TablePropertyChanged(this, arg);
            }
            get
            {
                return Data.DataString;
            }
        }

        public SolidColorBrush Background
        {
            set
            {
                Style.BackgroundColor = value.Color;
                TablePropertyChangedArgs arg = new TablePropertyChangedArgs()
                {
                    Data=value.Color,
                    PropertyName = "Background",
                    Operation = TablePropertyChangedArgs.ChangeProperty
                };
                TablePropertyChanged(this, arg);
            }
            get { return new SolidColorBrush(Style.BackgroundColor); }
        }

        public VerticalAlignment VerticalAlignment
        {
            set
            {
                Style.VerticalAlignment = value;
                TablePropertyChangedArgs arg = new TablePropertyChangedArgs()
                {
                    Data = value,
                    PropertyName = "VerticalAlignment",
                    Operation = TablePropertyChangedArgs.ChangeProperty
                };
                TablePropertyChanged(this, arg);
            }
            get { return Style.VerticalAlignment; }
        }

        public BooTableElementUnit()
        {
            Data = new BooTableDataUnit("");
            Style = new BooTableStyleUnit();
            TablePropertyChanged = null;
        }
        public BooTableElementUnit(int row,int column)
        {
            Data = new BooTableDataUnit("");
            Style = new BooTableStyleUnit(row,column);
            TablePropertyChanged = null;
        }
        public BooTableElementUnit(BooTableElementUnit unit)
        {
            Data = new BooTableDataUnit("");
            Style = new BooTableStyleUnit(unit.Style);
            TablePropertyChanged = null;
        }

        public void Load(BooTableElementUnit unit)
        {
            Data.Load(unit.Data);
            Style.Load(unit.Style);
            TablePropertyChanged(this, new TablePropertyChangedArgs() { 
                Operation = TablePropertyChangedArgs.Paste,
                Data=this
            });
        }

        public BooTableElementUnit Clone()
        {
            BooTableElementUnit unit = (BooTableElementUnit)this.MemberwiseClone();
            unit.Data = Data.Clone();
            unit.Style = Style.Clone();
            return unit;
        }
    }
}
